package com.immoc.demo.handler;

import com.sun.org.apache.regexp.internal.REUtil;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author zzy
 * @Description 处理所有的异常
 * @Date 2018/4/7 17:29
 * @Version 1.0
 **/
@ControllerAdvice //详情可以了解 https://blog.csdn.net/chenaschen/article/details/51291566
public class GlobalExceptionHandler {

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    private Map<String,Object> exceptionHandler(HttpServletRequest req,Exception e){
        Map<String,Object> modelMap = new HashMap<>();
        modelMap.put("success",false);
        modelMap.put("errMsg",e.getMessage());
        return modelMap;
    }
}
